<?php

// ----------------------------------------------------------------------
//this for multisite, they separated by database
// ----------------------------------------------------------------------
$GLOBALS['PNConfig']['Multisites']['multi'] = 1;
$flag = 0;
//$databaseName = getDatabaseList(); //read the file
$subdomain = explode(".", pnGetHost());
$dataBasePrefix = "okalimar_";


if(count($subdomain) == 3){
  if((strtolower($subdomain[0])!="www")){
      $dbname = $dataBasePrefix.$subdomain[0]; 
      $result = getDatabaseList(strtolower($dbname));

      //Check prefix isset
      if(strlen(trim($dataBasePrefix))>0){
      
        $databaseList = explode("_", $result[0]);      
        if(strtolower($subdomain[0]) == strtolower($databaseList[1])) {
            $PNConfig['DBInfo']['default']['dbname'] = $dbname;
            $flag = 1;
        }        
      }else{
        //Check not set prefix
        if(strtolower($subdomain[0]) == strtolower($result[0])) {
            $PNConfig['DBInfo']['default']['dbname'] = $result[0];
            $flag = 1;
        }      
      }
  }
}
if($flag == 0){
        //header( "refresh:0;url=http://www.phuketcity.com" );
        header('Location: http://www.okalimart.com/');
        exit;
}

function getDatabaseList($dbname=''){
  if(isset($dbname)){
    $query = "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '".$dbname."'";
    $db = mysql_connect($GLOBALS['PNConfig']['DBInfo']['default']['dbhost'],base64_decode($GLOBALS['PNConfig']['DBInfo']['default']['dbuname']),base64_decode($GLOBALS['PNConfig']['DBInfo']['default']['dbpass'])) or die("Database error");

    mysql_select_db("phuketcity2db", $db);
    mysql_query("set names 'utf8'");

    $DataArray = mysql_query($query);
    return mysql_fetch_array($DataArray);
  }else{
    return false;
  }

}

?>